(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminOwnerInfo: {
                owners: [],
                personRoles: [],
                total: 0,
                records: 1,
                moreCondition: false,
                _currentOwnerId: '',
                _eventName: '',
                conditions: {
                    personRole: '',
                    ownerId: '',
                    name: '',
                    link: '',
                    idCard: '',
                    roomNum: '',
                    roomId: '',
                    roomName: '',
                    personType: '',
                    communityId:'',
                },
                currentPage: DEFAULT_PAGE,
            }
        },
        _initMethod: function () {
            let _personRoles = [{
                statusCd: '',
                name: '全部'
            }];
            vc.getDict('building_owner', "person_role", function (_data) {
                _data.forEach(_d => {
                    _personRoles.push(_d);
                });
            });
            $that.adminOwnerInfo.personRoles = _personRoles;
        },
        _initEvent: function () {
            vc.on('selectAdminCommunity','changeCommunity',function(_community){
                $that.adminOwnerInfo.conditions.communityId = _community.communityId;
                $that._adminOwnerData($that.adminOwnerInfo.currentPage, DEFAULT_ROWS);
            })
            vc.on('adminOwner', 'adminOwnerData', function () {
                $that._adminOwnerData($that.adminOwnerInfo.currentPage, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that.adminOwnerInfo.currentPage = _currentPage;
                $that._adminOwnerData(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _adminOwnerData: function (_page, _row) {
                $that.adminOwnerInfo.conditions.page = _page;
                $that.adminOwnerInfo.conditions.row = _row;
                let param = {
                    params: $that.adminOwnerInfo.conditions
                }
                //发送get请求
                vc.http.apiGet('/owner.queryAdminOwners',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminOwnerInfo.total = _json.total;
                        $that.adminOwnerInfo.records = _json.records;
                        $that.adminOwnerInfo.owners = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.adminOwnerInfo.records,
                            dataCount: $that.adminOwnerInfo.total,
                            currentPage: _page
                        });
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
          
            //查询
            _queryOwnerMethod: function () {
                $that._adminOwnerData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetOwnerMethod: function () {
                $that.adminOwnerInfo.conditions = {
                    personRole: '',
                    ownerId: '',
                    name: '',
                    link: '',
                    idCard: '',
                    roomNum: '',
                    roomId: '',
                    roomName: '',
                    personType: ''
                };
                $that._adminOwnerData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.adminOwnerInfo.moreCondition) {
                    $that.adminOwnerInfo.moreCondition = false;
                } else {
                    $that.adminOwnerInfo.moreCondition = true;
                }
            },
            _viewOwnerFace: function (_url) {
                vc.emit('viewImage', 'showImage', {
                    url: _url
                });
            },
            swatchPersonRole: function (item) {
                $that.adminOwnerInfo.conditions.personRole = item.statusCd;
                $that._adminOwnerData(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _toAdminOwnerDetail(_owner){
                vc.jumpToPage('/#/pages/owner/adminOwnerDetail?ownerId='+_owner.ownerId);
            }
        }
    })
})(window.vc);